from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine,Column,String,Integer
from sqlalchemy.orm import sessionmaker
from database.dataconn import connection

Base = declarative_base()

engine = create_engine(connection.MYSQL_URL)

session = sessionmaker(engine)()

class Member(Base):
    __tablename__ = "member"  # 数据表名
    Mcardnum = Column(Integer, primary_key=True)
    Mname = Column(String)
    Mphone = Column(String)
    Mpoint = Column(Integer)

    def to_dict(self):
        model_dict = dict(self.__dict__)
        del model_dict['_sa_instance_state']
        return model_dict
    Base.to_dict = to_dict

    def single_to_sict(self):
        return {c.name: getattr(self, c.name) for c in self._table_.columns}

    def double_to_dict(self):
        result = {}
        for key in self.__mapper__.c.keys():
            if getattr(self,key) is not None:
                result[key] = str(getattr(self,key))
            else:
                result[key] = getattr(self,key)
        return result
def to_json(all_vendors):
    v = [ven.double_to_dict() for ven in all_vendors]
    return v